#pragma once
#include "common.h"
#include "NesCPU.h"
#include "NesCPUBus.h"
#include "NesPPU.h"
#include "NesGamePad.h"
#include "NesCartridge.h"
#include <stdio.h>

#include "NesPAPU.h"

enum TiggleType {
	NMI_PENING = 0x1,
	IRQ_PENING = 0x2,
	IRQ_ONESHOT = 0x4,
	IRQ_DMC_INT = 0x2,
	IRQ_HSYNC_INT = 0x2,
	IRQ_FRAME_INT = 0x2,
};
void DebugPrintf(const char* strOutputString, ...);

class IFcEvent
{
public:
	virtual bool OnSaveBundleOpen(bool issave) = 0;
	virtual bool OnSaveBundleClose() = 0;
	virtual void OnSaveBundleWrite(char* buf, int size) = 0;
	virtual void OnSaveBundleRead(char* buf, int size) = 0;
	virtual void OnAudioWrite(short* buf, int size) = 0;
};

class Famicom
{
private:
	bool mIsPalying = false;
	savebundle_t* savebundle_api = nullptr;
public:

	NesCPU* cpu = nullptr;
	NesCPUBus* cpubus = nullptr;
	NesPPU* ppu = nullptr;
	NesCartridge* cartridge = nullptr;
	NesGamePad* gamepad = nullptr;
	NesPAPU* apu = nullptr;
	SaveBundle* saveBundle = nullptr;
	IFcEvent* ifcevent = nullptr;

	Famicom();
	~Famicom();
	void UserInput(uint8_t index, uint8_t state) const;
	uint8_t* GetCanvas() const;
	int16_t* GetSamples(uint32_t* size) const;
	int ReloadRom(char* rom, size_t size);
	void EmulationFrame() const;
	void RenderPattern(uint8_t* mem) const;
	void Save() const;
	void Restore() const;
	void Reset() const;
	void SetSavebundle(savebundle_t* save);
	void SetSavebundle(SaveBundle* isave);
	void SetFcEvent(IFcEvent* isave);
};

